<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs">
<head>
<title>指针声明</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.21.2">
<link rel="shortcut icon" href="../../../common/favicon.ico">
<link rel="stylesheet" href="../../../common/ext.css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../../common/site_modules.css">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}#toc{display:none}.editsection{display:none}
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-css:7:15cea3ec788a65b5187d4018eed543bf */</style>

<script src="../../../common/startup_scripts.js"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"cpp/language/pointer","wgTitle":"cpp/language/pointer","wgCurRevisionId":59975,"wgArticleId":2744,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgBreakFrames":false,"wgPageContentLanguage":"zh","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"zh","wgMonthNames":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgMonthNamesShort":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgRelevantPageName":"cpp/language/pointer","wgUserVariant":"zh","wgRestrictionEdit":[],"wgRestrictionMove":[]});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,
"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"zh","language":"zh","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"gadget-MathJax":1,"gadget-ColiruCompiler":1});;},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});;},{},{});
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-js:7:258d7cd6aa9aa67dee25e01fb6a9e505 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-cpp {line-height: normal;}
.source-cpp li, .source-cpp pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for cpp
 * CSS class: source-cpp, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.cpp.source-cpp .de1, .cpp.source-cpp .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.cpp.source-cpp  {font-family:monospace;}
.cpp.source-cpp .imp {font-weight: bold; color: red;}
.cpp.source-cpp li, .cpp.source-cpp .li1 {font-weight: normal; vertical-align:top;}
.cpp.source-cpp .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.cpp.source-cpp .li2 {font-weight: bold; vertical-align:top;}
.cpp.source-cpp .kw1 {color: #0000dd;}
.cpp.source-cpp .kw2 {color: #0000ff;}
.cpp.source-cpp .kw3 {color: #0000dd;}
.cpp.source-cpp .kw4 {color: #0000ff;}
.cpp.source-cpp .co1 {color: #909090;}
.cpp.source-cpp .co2 {color: #339900;}
.cpp.source-cpp .coMULTI {color: #ff0000; font-style: italic;}
.cpp.source-cpp .es0 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es1 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es2 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es3 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es4 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es5 {color: #008000; font-weight: bold;}
.cpp.source-cpp .br0 {color: #008000;}
.cpp.source-cpp .sy0 {color: #008000;}
.cpp.source-cpp .sy1 {color: #000080;}
.cpp.source-cpp .sy2 {color: #000040;}
.cpp.source-cpp .sy3 {color: #000040;}
.cpp.source-cpp .sy4 {color: #008080;}
.cpp.source-cpp .st0 {color: #008000;}
.cpp.source-cpp .nu0 {color: #000080;}
.cpp.source-cpp .nu6 {color: #000080;}
.cpp.source-cpp .nu8 {color: #000080;}
.cpp.source-cpp .nu12 {color: #000080;}
.cpp.source-cpp .nu16 {color:#000080;}
.cpp.source-cpp .nu17 {color:#000080;}
.cpp.source-cpp .nu18 {color:#000080;}
.cpp.source-cpp .nu19 {color:#000080;}
.cpp.source-cpp .ln-xtra, .cpp.source-cpp li.ln-xtra, .cpp.source-cpp div.ln-xtra {background-color: #ffc;}
.cpp.source-cpp span.xtra { display:block; }

/*]]>*/
</style><style type="text/css">/*<![CDATA[*/
.source-text {line-height: normal;}
.source-text li, .source-text pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for text
 * CSS class: source-text, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.text.source-text .de1, .text.source-text .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.text.source-text  {font-family:monospace;}
.text.source-text .imp {font-weight: bold; color: red;}
.text.source-text li, .text.source-text .li1 {font-weight: normal; vertical-align:top;}
.text.source-text .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.text.source-text .li2 {font-weight: bold; vertical-align:top;}
.text.source-text .ln-xtra, .text.source-text li.ln-xtra, .text.source-text div.ln-xtra {background-color: #ffc;}
.text.source-text span.xtra { display:block; }

/*]]>*/
</style><!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_language_pointer skin-cppreference2 action-view cpp-navbar">
        <!-- header -->
        <!-- /header -->
        <!-- content -->
<div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
<h1 id="firstHeading" class="firstHeading">指针声明</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">来自cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../../cpp.html" title="cpp">cpp</a>‎ | <a href="../language.html" title="cpp/language">language</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr"><div class="t-navbar" style=""><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../cpp.html" title="cpp"> C++</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="line-height:1.1em;">
<tr class="t-nv"><td colspan="5"> <a href="../language.html" title="cpp/language">语言</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../header.html" title="cpp/header">标准库头文件</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../freestanding.html" title="cpp/freestanding"> 自立与有宿主实现</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../named_req.html" title="cpp/named req">具名要求</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../utility.html#.E8.AF.AD.E8.A8.80.E6.94.AF.E6.8C.81" title="cpp/utility">语言支持库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../concepts.html" title="cpp/concepts">概念库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../error.html" title="cpp/error">诊断库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../utility.html" title="cpp/utility">工具库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../string.html" title="cpp/string">字符串库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="https://zh.cppreference.com/w/cpp/container" title="cpp/container">容器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../iterator.html" title="cpp/iterator">迭代器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../ranges.html" title="cpp/ranges"> 范围库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../algorithm.html" title="cpp/algorithm">算法库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../numeric.html" title="cpp/numeric">数值库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../io.html" title="cpp/io">输入/输出库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../locale.html" title="cpp/locale">本地化库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../regex.html" title="cpp/regex">正则表达式库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../atomic.html" title="cpp/atomic">原子操作库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../thread.html" title="cpp/thread">线程支持库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../filesystem.html" title="cpp/filesystem">文件系统库</a> <span class="t-mark-rev t-since-cxx17">(C++17)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../experimental.html" title="cpp/experimental">技术规范</a> </td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../language.html" title="cpp/language">C++ 语言</a></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="declarations.html" title="cpp/language/declarations">声明</a><div class="t-navbar-menu"><div><div style="display:inline-block">
<div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h2"><td colspan="5"> 概览 </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="declarations.html" title="cpp/language/declarations">声明语法</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="declarations.html#.E8.AF.B4.E6.98.8E.E7.AC.A6" title="cpp/language/declarations"> 声明说明符序列</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="declarations.html#.E5.A3.B0.E6.98.8E.E7.AC.A6" title="cpp/language/declarations"> 声明符</a> </td></tr>
<tr class="t-nv-h2"><td colspan="5"> 说明符 </td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="typedef.html" title="cpp/language/typedef"><span class="t-lines"><span>typedef</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="inline.html" title="cpp/language/inline"><span class="t-lines"><span>inline</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="virtual.html" title="cpp/language/virtual"> virtual 函数说明符</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="explicit.html" title="cpp/language/explicit"> explicit 函数说明符</a> </td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="friend.html" title="cpp/language/friend"><span class="t-lines"><span>friend</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="constexpr.html" title="cpp/language/constexpr"><span class="t-lines"><span>constexpr</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="consteval.html" title="cpp/language/consteval"><span class="t-lines"><span>consteval</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="constinit.html" title="cpp/language/constinit"><span class="t-lines"><span>constinit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="storage_duration.html" title="cpp/language/storage duration"> 存储类说明符</a> </td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="class.html" title="cpp/language/class"><span class="t-lines"><span>class</span><span>struct</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="union.html" title="cpp/language/union"><span class="t-lines"><span>union</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="enum.html" title="cpp/language/enum"><span class="t-lines"><span>enum</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="decltype.html" title="cpp/language/decltype"><span class="t-lines"><span>decltype</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="auto.html" title="cpp/language/auto"><span class="t-lines"><span>auto</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="alignas.html" title="cpp/language/alignas"><span class="t-lines"><span>alignas</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="cv.html" title="cpp/language/cv"><span class="t-lines"><span>const</span><span>volatile</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="elaborated_type_specifier.html" title="cpp/language/elaborated type specifier">详述类型说明符</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="attributes.html" title="cpp/language/attributes"> 属性</a><span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h2"><td colspan="5"> 声明符 </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="reference.html" title="cpp/language/reference"> 引用</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <strong class="selflink"> 指针</strong> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="array.html" title="cpp/language/array"> 数组</a> </td></tr>
<tr class="t-nv-h2"><td colspan="5"> 块声明 </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="declarations.html" title="cpp/language/declarations"> 简单声明</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="structured_binding.html" title="cpp/language/structured binding">结构化绑定声明</a> <span class="t-mark-rev t-since-cxx17">(C++17)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="type_alias.html" title="cpp/language/type alias"> 别名声明</a><span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="namespace_alias.html" title="cpp/language/namespace alias"> 命名空间别名定义</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="using_declaration.html" title="cpp/language/using declaration"> using 声明</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="namespace.html#using_.E6.8C.87.E4.BB.A4" title="cpp/language/namespace"> using 指令</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="static_assert.html" title="cpp/language/static assert"> static_assert 声明</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="asm.html" title="cpp/language/asm"> asm 声明</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="enum.html" title="cpp/language/enum"> 不可见 enum 声明</a><span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv-h2"><td colspan="5"> 其他声明 </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="namespace.html" title="cpp/language/namespace"> 命名空间定义</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="function.html" title="cpp/language/function"> 函数声明</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="class_template.html" title="cpp/language/class template"> 类模板声明</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="function_template.html" title="cpp/language/function template"> 函数模板声明</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="class_template.html#.E6.98.BE.E5.BC.8F.E5.AE.9E.E4.BE.8B.E5.8C.96" title="cpp/language/class template"> 显式模板实例化</a><span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="template_specialization.html" title="cpp/language/template specialization"> 显式模板特化</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="language_linkage.html" title="cpp/language/language linkage"> 连接说明</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="declarations.html" title="cpp/language/declarations"> 属性声明</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="declarations.html" title="cpp/language/declarations"> 空声明</a> </td></tr>
</table></div></td></tr>
</table></div>
</div><div></div></div></div></div><div class="t-navbar-sep"> </div></div>
<p>声明指针或指向成员指针类型的变量。
</p>
<h3><span class="mw-headline" id=".E8.AF.AD.E6.B3.95">语法</span></h3>
<p>指针的声明是简单声明，其<a href="declarations.html" title="cpp/language/declarations">声明符</a>拥有下列形式
</p>
<table class="t-sdsc-begin">

<tr>
<td colspan="10" class="t-sdsc-sep">
</td></tr>
<tr class="t-sdsc">
<td> <code><b>*</b></code> <span class="t-spar">attr</span><span class="t-mark">(可选)</span> <span class="t-spar">cv</span><span class="t-mark">(可选)</span> <span class="t-spar">声明符</span>
</td>
<td> (1)
</td>
<td class="t-sdsc-nopad">
</td></tr>



<tr>
<td colspan="10" class="t-sdsc-sep">
</td></tr>
<tr class="t-sdsc">
<td> <span class="t-spar">嵌套名说明符</span> <code><b>*</b></code> <span class="t-spar">attr</span><span class="t-mark">(可选)</span> <span class="t-spar">cv</span><span class="t-mark">(可选)</span> <span class="t-spar">声明符</span>
</td>
<td> (2)
</td>
<td class="t-sdsc-nopad">
</td></tr>



<tr>
<td colspan="10" class="t-sdsc-sep">
</td></tr></table>
<div class="t-li1"><span class="t-li">1)</span> <b>指针声明符</b>：声明 <span class="t-c"><span class="mw-geshi cpp source-cpp">S<span class="sy2">*</span> D<span class="sy4">;</span></span></span> 将 <code>D</code> 声明为指向 <span class="t-spar">嵌套名说明符</span> <code>S</code> 所确定类型的指针。</div>
<div class="t-li1"><span class="t-li">2)</span> <b>成员指针声明符</b>：声明 <span class="t-c"><span class="mw-geshi cpp source-cpp">S C<span class="sy4">::</span><span class="sy2">*</span> D<span class="sy4">;</span></span></span> 将 <code>D</code> 声明为指向 <code>C</code> 的 <span class="t-spar">嵌套名说明符</span> <code>S</code> 所确定类型的非静态数据成员的指针。</div>
<table class="t-par-begin">


<tr class="t-par">
<td>  <span class="t-spar">声明符</span>
</td>
<td> -
</td>
<td> 除引用声明符之外的任意<a href="declarations.html" title="cpp/language/declarations">声明符</a>（无指向引用的指针）。它可以是另一指针声明符（允许指向指针的指针）
</td></tr>
<tr class="t-par">
<td>  <span class="t-spar">attr</span><span class="t-mark-rev t-since-cxx11">(C++11)</span>
</td>
<td> -
</td>
<td> <a href="attributes.html" title="cpp/language/attributes">属性</a>的可选列表
</td></tr>
<tr class="t-par">
<td>  <span class="t-spar">cv</span>
</td>
<td> -
</td>
<td> 应用到被声明指针的 const/volatile 限定（而并非被指向类型，其限定是 <span class="t-spar">声明说明符序列</span> 的一部分）
</td></tr>
<tr class="t-par">
<td>  <span class="t-spar">嵌套名说明符</span>
</td>
<td> -
</td>
<td> <a href="name.html#.E6.9C.89.E9.99.90.E5.AE.9A.E7.9A.84.E6.A0.87.E8.AF.86.E7.AC.A6" title="cpp/language/identifiers">名字和作用域解析运算符 <code><b>::</b></code> 的序列</a>
</td></tr></table>
<p>无指向<a href="reference.html" title="cpp/language/reference">引用</a>的指针，无指向<a href="bit_field.html" title="cpp/language/bit field">位域</a>的指针。
当没有详述地提及“指针”时，通常不包含指向（非静态）成员的指针。
</p>
<h3><span class="mw-headline" id=".E6.8C.87.E9.92.88">指针</span></h3>
<p>指针类型的值是下列之一：
</p>
<ul><li> <i>指向对象或函数的指针</i>（该情况下说该指针<i>指向</i>函数或对象），或
</li><li> <i>对象末尾后指针</i>，或
</li><li> 该类型的<i><a href="pointer.html#.E7.A9.BA.E6.8C.87.E9.92.88">空指针值</a></i>，或
</li><li> <i>无效指针值</i>。
</li></ul>
<p>指向对象的指针<i>表示其地址</i>，为内存中对象所占用的首字节的地址。对象的末尾后指针亦<i>表示地址</i>，为内存中对象所占用的存储之后的首个字节的地址。
</p><p>注意，两个表示同一地址的指针可能拥有不同的值。
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> C <span class="br0">{</span>
   <span class="kw4">int</span> x, y<span class="sy4">;</span>
<span class="br0">}</span> c<span class="sy4">;</span>
 
<span class="kw4">int</span><span class="sy2">*</span> px <span class="sy1">=</span> <span class="sy3">&amp;</span>c.<span class="me1">x</span><span class="sy4">;</span>   <span class="co1">// px 的值为“指向 c.x 的指针”</span>
<span class="kw4">int</span><span class="sy2">*</span> pxe<span class="sy1">=</span> px <span class="sy2">+</span> <span class="nu0">1</span><span class="sy4">;</span> <span class="co1">// pxe 的值为“ c.x 的尾后指针”</span>
<span class="kw4">int</span><span class="sy2">*</span> py <span class="sy1">=</span> <span class="sy3">&amp;</span>c.<span class="me1">y</span><span class="sy4">;</span>   <span class="co1">// py 的值为“指向 c.y 的指针”</span>
 
<a href="../error/assert.html"><span class="kw774">assert</span></a><span class="br0">(</span>pxe <span class="sy1">==</span> py<span class="br0">)</span><span class="sy4">;</span> <span class="co1">// == 测试两个指针是否表示相同地址</span>
                   <span class="co1">// 可能或可能不引发断言</span>
 
<span class="sy2">*</span>pxe <span class="sy1">=</span> <span class="nu0">1</span><span class="sy4">;</span> <span class="co1">// 即使未引发断言，亦为未定义行为</span></pre></div></div>
<p><br>
通过无效指针值间接寻址，和将无效指针值传递给解分配函数均拥有未定义行为。无效指针值的任何其他用法拥有由实现定义的行为。
</p>
<h4><span class="mw-headline" id=".E5.AF.B9.E8.B1.A1.E6.8C.87.E9.92.88">对象指针</span></h4>
<p>对象指针，能以应用于任何对象类型（包含另一指针类型）的表达式的<a href="operator_member_access.html" title="cpp/language/operator member access">取址运算符</a>的返回值初始化：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">int</span> n<span class="sy4">;</span>
<span class="kw4">int</span><span class="sy2">*</span> np <span class="sy1">=</span> <span class="sy3">&amp;</span>n<span class="sy4">;</span> <span class="co1">// int 的指针</span>
<span class="kw4">int</span><span class="sy2">*</span> <span class="kw4">const</span><span class="sy2">*</span> npp <span class="sy1">=</span> <span class="sy3">&amp;</span>np<span class="sy4">;</span> <span class="co1">// 非 const int 的 const 指针的非 const 指针</span>
 
<span class="kw4">int</span> a<span class="br0">[</span><span class="nu0">2</span><span class="br0">]</span><span class="sy4">;</span>
<span class="kw4">int</span> <span class="br0">(</span><span class="sy2">*</span>ap<span class="br0">)</span><span class="br0">[</span><span class="nu0">2</span><span class="br0">]</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>a<span class="sy4">;</span> <span class="co1">// int 的数组的指针</span>
 
<span class="kw1">struct</span> S <span class="br0">{</span> <span class="kw4">int</span> n<span class="sy4">;</span> <span class="br0">}</span><span class="sy4">;</span>
S s <span class="sy1">=</span> <span class="br0">{</span><span class="nu0">1</span><span class="br0">}</span><span class="sy4">;</span>
<span class="kw4">int</span><span class="sy2">*</span> sp <span class="sy1">=</span> <span class="sy3">&amp;</span>s.<span class="me1">n</span><span class="sy4">;</span> <span class="co1">// 指向作为 s 的成员的 int 的指针</span></pre></div></div>
<p>指针可作为内建间接寻址运算符（一元 <code>operator*</code>）的操作数，返回指代被指向对象的<a href="value_category.html" title="cpp/language/value category">左值表达式</a>：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">int</span> n<span class="sy4">;</span>
<span class="kw4">int</span><span class="sy2">*</span> p <span class="sy1">=</span> <span class="sy3">&amp;</span>n<span class="sy4">;</span>     <span class="co1">// 指向 n 的指针</span>
<span class="kw4">int</span><span class="sy3">&amp;</span> r <span class="sy1">=</span> <span class="sy2">*</span>p<span class="sy4">;</span>     <span class="co1">// 绑定到指代 n 的左值表达式的引用</span>
r <span class="sy1">=</span> <span class="nu0">7</span><span class="sy4">;</span>           <span class="co1">// 存储 int 7 于 n</span>
<a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="sy2">*</span>p<span class="sy4">;</span> <span class="co1">// 左值到右值隐式转换从 n 读取值</span></pre></div></div>
<p>指向类对象的指针亦可作为成员访问运算符 <a href="operator_member_access.html#.E5.86.85.E5.BB.BA.E7.9A.84.E6.88.90.E5.91.98.E8.AE.BF.E9.97.AE.E8.BF.90.E7.AE.97.E7.AC.A6" title="cpp/language/operator member access">operator-&gt;</a> 和 <a href="operator_member_access.html#.E5.86.85.E5.BB.BA.E7.9A.84.E6.88.90.E5.91.98.E6.8C.87.E9.92.88.E8.AE.BF.E9.97.AE.E8.BF.90.E7.AE.97.E7.AC.A6" title="cpp/language/operator member access">operator-&gt;*</a> 的左侧操作数。
</p><p>由于<a href="implicit_cast.html" title="cpp/language/implicit conversion">数组到指针</a>隐式转换的原因，可以以数组类型的表达式初始化指向数组首元素的指针：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">int</span> a<span class="br0">[</span><span class="nu0">2</span><span class="br0">]</span><span class="sy4">;</span>
<span class="kw4">int</span><span class="sy2">*</span> p1 <span class="sy1">=</span> a<span class="sy4">;</span> <span class="co1">// 指向数组 a 首元素 a[0]（一个 int）的指针</span>
 
<span class="kw4">int</span> b<span class="br0">[</span><span class="nu0">6</span><span class="br0">]</span><span class="br0">[</span><span class="nu0">3</span><span class="br0">]</span><span class="br0">[</span><span class="nu0">8</span><span class="br0">]</span><span class="sy4">;</span>
<span class="kw4">int</span> <span class="br0">(</span><span class="sy2">*</span>p2<span class="br0">)</span><span class="br0">[</span><span class="nu0">3</span><span class="br0">]</span><span class="br0">[</span><span class="nu0">8</span><span class="br0">]</span> <span class="sy1">=</span> b<span class="sy4">;</span> <span class="co1">// 指向数组 b 首元素 b[0] 的指针，</span>
                     <span class="co1">// 被指者为 int 的 8 元素数组的 3 元素数组</span></pre></div></div>
<p>由于指针的<a href="implicit_cast.html" title="cpp/language/implicit conversion">派生类到基类</a>隐式转换的原因，可以以派生类的地址初始化指向基类的指针：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> Base <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span>
<span class="kw1">struct</span> Derived <span class="sy4">:</span> Base <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span>
 
Derived d<span class="sy4">;</span>
Base<span class="sy2">*</span> p <span class="sy1">=</span> <span class="sy3">&amp;</span>d<span class="sy4">;</span></pre></div></div>
<p>若 <code>Derived</code> 是<a href="object.html#.E5.A4.9A.E6.80.81.E5.AF.B9.E8.B1.A1" title="cpp/language/object">多态的</a>，则这种指针可用于进行<a href="virtual.html" title="cpp/language/virtual">虚函数调用</a>。
</p><p>某些<a href="operator_arithmetic.html#.E5.8A.A0.E6.B3.95.E6.80.A7.E8.BF.90.E7.AE.97.E7.AC.A6" title="cpp/language/operator arithmetic">加法、减法</a>、<a href="operator_incdec.html" title="cpp/language/operator incdec">自增和自减</a>运算符对于指向数组元素的指针有定义：这种指针满足<a href="../named_req/RandomAccessIterator.html" title="cpp/named req/RandomAccessIterator"><i>遗留随机访问迭代器</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(LegacyRandomAccessIterator)</span> </a>要求，并允许 C++ 库<a href="../algorithm.html" title="cpp/algorithm">算法</a>工作于原始数组上。
</p><p>某些情况下，<a href="operator_comparison.html#.E6.8C.87.E9.92.88.E6.AF.94.E8.BE.83.E8.BF.90.E7.AE.97.E7.AC.A6" title="cpp/language/operator comparison">比较运算符</a>对指针有定义：两个表示相同地址的指针比较相等，两个空指针值比较相等，指向同一数组中的元素的指针的比较与各元素的数组下标的比较方式相同，而指向拥有相同<a href="access.html" title="cpp/language/access">成员访问</a>的非静态数据成员的指针以各成员的声明顺序进行比较。
</p><p>多数实现亦为随机来源的指针提供<a href="https://en.wikipedia.org/wiki/Total_order#Strict_total_order" class="extiw" title="enwiki:Total order">严格全序</a>，例如将它们实现为连续虚拟地址空间中的地址。未能做到的实现（例如，其中并非指针的所有位都是内存地址的一部分因而在比较时必须忽略之，或者要求附带的计算，或者指针与整数并非一对一关系），为指针提供了具有此项保证的 <span class="t-lc"><a href="../utility/functional/less.html" title="cpp/utility/functional/less">std::less</a></span> 特化。这使得可在关联容器（如 <span class="t-lc"><a href="../container/set.html" title="cpp/container/set">std::set</a></span> 或 <span class="t-lc"><a href="../container/map.html" title="cpp/container/map">std::map</a></span>）中使用所有随机来源的指针。
</p>
<h4><span class="mw-headline" id="void_.E7.9A.84.E6.8C.87.E9.92.88">void 的指针</span></h4>
<p>指向任意类型对象的指针，可<a href="implicit_cast.html" title="cpp/language/implicit conversion">隐式转换成</a>指向 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">void</span></span></span> 的指针（可选地有 <a href="cv.html" title="cpp/language/cv">cv 限定</a>）；不改变其值。逆向的转换要求 <a href="static_cast.html" title="cpp/language/static cast">static_cast</a> 或<a href="explicit_cast.html" title="cpp/language/explicit cast">显式转型</a>，生成其原指针值：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">int</span> n <span class="sy1">=</span> <span class="nu0">1</span><span class="sy4">;</span>
<span class="kw4">int</span><span class="sy2">*</span> p1 <span class="sy1">=</span> <span class="sy3">&amp;</span>n<span class="sy4">;</span>
<span class="kw4">void</span><span class="sy2">*</span> pv <span class="sy1">=</span> p1<span class="sy4">;</span>
<span class="kw4">int</span><span class="sy2">*</span> p2 <span class="sy1">=</span> <span class="kw1">static_cast</span><span class="sy1">&lt;</span><span class="kw4">int</span><span class="sy2">*</span><span class="sy1">&gt;</span><span class="br0">(</span>pv<span class="br0">)</span><span class="sy4">;</span>
<a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="sy2">*</span>p2 <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="co1">// 打印 1</span></pre></div></div>
<p>若原指针指向某多态类型对象中的基类子对象，则可用 <a href="dynamic_cast.html" title="cpp/language/dynamic cast">dynamic_cast</a> 获得指向最终派生类型的完整对象的 <code>void*</code>。
</p><p>void 指针用于传递未知类型对象，这在 C 接口中常见：<span class="t-lc"><a href="../memory/c/malloc.html" title="cpp/memory/c/malloc">std::malloc</a></span> 返回 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">void</span><span class="sy2">*</span></span></span>，<span class="t-lc"><a href="../algorithm/qsort.html" title="cpp/algorithm/qsort">std::qsort</a></span> 期待接受两个 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">const</span> <span class="kw4">void</span><span class="sy2">*</span></span></span> 参数的用户提供回调。<a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html">pthread_create</a> 期待接受并返回 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">void</span><span class="sy2">*</span></span></span> 的用户提供的回调。所有情况下，调用方负责在使用前将指针转型到正确类型。
</p><p><br>
</p>
<h4><span class="mw-headline" id=".E5.87.BD.E6.95.B0.E6.8C.87.E9.92.88">函数指针</span></h4>
<p>函数指针能以非成员函数或静态成员函数的地址初始化。由于<a href="implicit_cast.html" title="cpp/language/implicit conversion">函数到指针</a>隐式转换的原因，取址运算符是可选的：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">void</span> f<span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span><span class="sy4">;</span>
<span class="kw4">void</span> <span class="br0">(</span><span class="sy2">*</span>p1<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>f<span class="sy4">;</span>
<span class="kw4">void</span> <span class="br0">(</span><span class="sy2">*</span>p2<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> f<span class="sy4">;</span> <span class="co1">// 与 &amp;f 相同</span></pre></div></div>
<p>不同于函数或函数的引用，函数指针是对象，从而能存储于数组、被复制、被赋值等。
</p><p>函数指针可用作<a href="operator_other.html" title="cpp/language/operator other">函数调用运算符</a>的左侧操作数，这会调用被指向的函数：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">int</span> f<span class="br0">(</span><span class="kw4">int</span> n<span class="br0">)</span>
<span class="br0">{</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> n <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span>
    <span class="kw1">return</span> n <span class="sy2">*</span> n<span class="sy4">;</span>
<span class="br0">}</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">int</span> <span class="br0">(</span><span class="sy2">*</span>p<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> f<span class="sy4">;</span>
    <span class="kw4">int</span> x <span class="sy1">=</span> p<span class="br0">(</span><span class="nu0">7</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>解引用函数指针生成标识被指向函数的左值：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">int</span> f<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
<span class="kw4">int</span> <span class="br0">(</span><span class="sy2">*</span>p<span class="br0">)</span><span class="br0">(</span><span class="br0">)</span> <span class="sy1">=</span> f<span class="sy4">;</span>  <span class="co1">// 指针 p 指向 f</span>
<span class="kw4">int</span> <span class="br0">(</span><span class="sy3">&amp;</span>r<span class="br0">)</span><span class="br0">(</span><span class="br0">)</span> <span class="sy1">=</span> <span class="sy2">*</span>p<span class="sy4">;</span> <span class="co1">// 将标识 f 的左值绑定到引用</span>
r<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>             <span class="co1">// 通过左值引用调用函数 f</span>
<span class="br0">(</span><span class="sy2">*</span>p<span class="br0">)</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>          <span class="co1">// 通过函数左值调用函数 f</span>
p<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>             <span class="co1">// 直接通过指针调用函数 f</span></pre></div></div>
<p>若只有一个重载匹配指针类型的话，函数指针可以从可包含函数、函数模板特化及函数模板的一个重载集进行初始化（细节见<a href="overloaded_address.html" title="cpp/language/overloaded address">重载函数的地址</a>）：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">typename</span> T<span class="sy1">&gt;</span> T f<span class="br0">(</span>T n<span class="br0">)</span> <span class="br0">{</span> <span class="kw1">return</span> n<span class="sy4">;</span> <span class="br0">}</span>
<span class="kw4">double</span> f<span class="br0">(</span><span class="kw4">double</span> n<span class="br0">)</span> <span class="br0">{</span> <span class="kw1">return</span> n<span class="sy4">;</span> <span class="br0">}</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">int</span> <span class="br0">(</span><span class="sy2">*</span>p<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> f<span class="sy4">;</span> <span class="co1">// 实例化并选择 f&lt;int&gt;</span>
<span class="br0">}</span></pre></div></div>
<p><a href="operator_comparison.html#.E6.8C.87.E9.92.88.E6.AF.94.E8.BE.83.E8.BF.90.E7.AE.97.E7.AC.A6" title="cpp/language/operator comparison">相等比较运算符</a>对于函数指针有定义（若指向同一函数则它们比较相等）。
</p>
<h3><span class="mw-headline" id=".E6.88.90.E5.91.98.E6.8C.87.E9.92.88">成员指针</span></h3>
<h4><span class="mw-headline" id=".E6.95.B0.E6.8D.AE.E6.88.90.E5.91.98.E6.8C.87.E9.92.88">数据成员指针</span></h4>
<p>指向作为类 <code>C</code> 的成员的非静态数据成员 <code>m</code> 的指针，能准确地以表达式 <code>&amp;C::m</code> 初始化。在 C 的成员函数中，如 <code>&amp;(C::m)</code> 或 <code>&amp;m</code> 这样的表达式不构成指向成员指针。
</p><p>这种指针能用作<a href="operator_member_access.html" title="cpp/language/operator member access">成员指针访问运算符</a> <code>operator.*</code> 与 <code>operator-&gt;*</code> 的右侧操作数：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> C <span class="br0">{</span> <span class="kw4">int</span> m<span class="sy4">;</span> <span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">int</span> C<span class="sy4">::</span><span class="sy2">*</span> p <span class="sy1">=</span> <span class="sy3">&amp;</span>C<span class="sy4">::</span><span class="me2">m</span><span class="sy4">;</span>          <span class="co1">// 指向类 C 的数据成员 m</span>
    C c <span class="sy1">=</span> <span class="br0">{</span><span class="nu0">7</span><span class="br0">}</span><span class="sy4">;</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> c.<span class="sy2">*</span>p <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span>   <span class="co1">// 打印 7</span>
    C<span class="sy2">*</span> cp <span class="sy1">=</span> <span class="sy3">&amp;</span>c<span class="sy4">;</span>
    cp<span class="sy2">-</span><span class="sy1">&gt;</span>m <span class="sy1">=</span> <span class="nu0">10</span><span class="sy4">;</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> cp<span class="sy2">-</span><span class="sy1">&gt;</span><span class="sy2">*</span>p <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="co1">// 打印 10</span>
<span class="br0">}</span></pre></div></div>
<p>指向可访问无歧义非虚基类的数据成员的指针，可以<a href="implicit_cast.html" title="cpp/language/implicit conversion">隐式转换</a>成指向派生类的同一数据成员的指针：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> Base <span class="br0">{</span> <span class="kw4">int</span> m<span class="sy4">;</span> <span class="br0">}</span><span class="sy4">;</span>
<span class="kw1">struct</span> Derived <span class="sy4">:</span> Base <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">int</span> Base<span class="sy4">::</span><span class="sy2">*</span> bp <span class="sy1">=</span> <span class="sy3">&amp;</span>Base<span class="sy4">::</span><span class="me2">m</span><span class="sy4">;</span>
    <span class="kw4">int</span> Derived<span class="sy4">::</span><span class="sy2">*</span> dp <span class="sy1">=</span> bp<span class="sy4">;</span>
    Derived d<span class="sy4">;</span>
    d.<span class="me1">m</span> <span class="sy1">=</span> <span class="nu0">1</span><span class="sy4">;</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> d.<span class="sy2">*</span>dp <span class="sy1">&lt;&lt;</span> <span class="st0">' '</span> <span class="sy1">&lt;&lt;</span> d.<span class="sy2">*</span>bp <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="co1">// 打印 1 1</span>
<span class="br0">}</span></pre></div></div>
<p>相反方向的转换，即从指向派生类的数据成员的指针到指向无歧义非虚基类的数据成员的指针，允许由 <a href="static_cast.html" title="cpp/language/static cast">static_cast</a> 和<a href="explicit_cast.html" title="cpp/language/explicit cast">显式转型</a>来进行，即使基类并无该成员（但当用该指针访问时，最终派生类中有）亦可：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> Base <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span>
<span class="kw1">struct</span> Derived <span class="sy4">:</span> Base <span class="br0">{</span> <span class="kw4">int</span> m<span class="sy4">;</span> <span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">int</span> Derived<span class="sy4">::</span><span class="sy2">*</span> dp <span class="sy1">=</span> <span class="sy3">&amp;</span>Derived<span class="sy4">::</span><span class="me2">m</span><span class="sy4">;</span>
    <span class="kw4">int</span> Base<span class="sy4">::</span><span class="sy2">*</span> bp <span class="sy1">=</span> <span class="kw1">static_cast</span><span class="sy1">&lt;</span><span class="kw4">int</span> Base<span class="sy4">::</span><span class="sy2">*</span><span class="sy1">&gt;</span><span class="br0">(</span>dp<span class="br0">)</span><span class="sy4">;</span>
 
    Derived d<span class="sy4">;</span>
    d.<span class="me1">m</span> <span class="sy1">=</span> <span class="nu0">7</span><span class="sy4">;</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> d.<span class="sy2">*</span>bp <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="co1">// OK：打印 7</span>
 
    Base b<span class="sy4">;</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> b.<span class="sy2">*</span>bp <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="co1">// 未定义行为</span>
<span class="br0">}</span></pre></div></div>
<p>成员指针的被指向类型也可以是成员指针自身：成员指针可为多级，而且在每级可以有不同的 cv 限定。亦允许指针和成员指针的混合多级组合：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> A
<span class="br0">{</span>
    <span class="kw4">int</span> m<span class="sy4">;</span>
    <span class="co1">// 指向非 const 成员的 const 指针</span>
    <span class="kw4">int</span> A<span class="sy4">::</span><span class="sy2">*</span> <span class="kw4">const</span> p<span class="sy4">;</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="co1">// 指向数据成员的非 const 指针，该成员是指向非 const 成员的 const 指针</span>
    <span class="kw4">int</span> A<span class="sy4">::</span><span class="sy2">*</span> <span class="kw4">const</span> A<span class="sy4">::</span><span class="sy2">*</span> p1 <span class="sy1">=</span> <span class="sy3">&amp;</span>A<span class="sy4">::</span><span class="me2">p</span><span class="sy4">;</span>
 
    <span class="kw4">const</span> A a <span class="sy1">=</span> <span class="br0">{</span><span class="nu0">1</span>, <span class="sy3">&amp;</span>A<span class="sy4">::</span><span class="me2">m</span><span class="br0">}</span><span class="sy4">;</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> a.<span class="sy2">*</span><span class="br0">(</span>a.<span class="sy2">*</span>p1<span class="br0">)</span> <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="co1">// 打印 1</span>
 
    <span class="co1">// 指向 const 的成员指针的常规非 const 指针</span>
    <span class="kw4">int</span> A<span class="sy4">::</span><span class="sy2">*</span> <span class="kw4">const</span><span class="sy2">*</span> p2 <span class="sy1">=</span> <span class="sy3">&amp;</span>a.<span class="me1">p</span><span class="sy4">;</span>
    <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> a.<span class="sy2">**</span>p2 <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="co1">// 打印 1</span>
<span class="br0">}</span></pre></div></div>
<h4><span class="mw-headline" id=".E6.88.90.E5.91.98.E5.87.BD.E6.95.B0.E6.8C.87.E9.92.88">成员函数指针</span></h4>
<p>指向作为类 <code>C</code> 的成员的非静态成员函数 <code>f</code> 的指针，可准确地以表达式 <code>&amp;C::f</code> 初始化。在 C 的成员函数内，如 <code>&amp;(C::f)</code> 或 <code>&amp;f</code> 这样的表达式不构成成员函数指针。
</p><p>这种指针可以用作<a href="operator_member_access.html" title="cpp/language/operator member access">成员指针访问运算符</a> <code>operator.*</code> 与 <code>operator-&gt;*</code> 的右操作数。<a href="value_category.html#.E6.9C.AA.E5.86.B3.E6.88.90.E5.91.98.E5.87.BD.E6.95.B0.E8.B0.83.E7.94.A8" title="cpp/language/value category">结果表达式</a>只能用作函数调用运算符的左侧操作数：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> C
<span class="br0">{</span>
    <span class="kw4">void</span> f<span class="br0">(</span><span class="kw4">int</span> n<span class="br0">)</span> <span class="br0">{</span> <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> n <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="br0">}</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">void</span> <span class="br0">(</span>C<span class="sy4">::</span><span class="sy2">*</span> p<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>C<span class="sy4">::</span><span class="me2">f</span><span class="sy4">;</span> <span class="co1">// 指向类 C 的成员函数 f 的指针</span>
    C c<span class="sy4">;</span>
    <span class="br0">(</span>c.<span class="sy2">*</span>p<span class="br0">)</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy4">;</span>                  <span class="co1">// 打印 1</span>
    C<span class="sy2">*</span> cp <span class="sy1">=</span> <span class="sy3">&amp;</span>c<span class="sy4">;</span>
    <span class="br0">(</span>cp<span class="sy2">-</span><span class="sy1">&gt;</span><span class="sy2">*</span>p<span class="br0">)</span><span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span><span class="sy4">;</span>                <span class="co1">// 打印 2</span>
<span class="br0">}</span></pre></div></div>
<p><br>
指向基类的成员函数的指针可以<a href="implicit_cast.html" title="cpp/language/implicit conversion">隐式转换</a>成指向派生类的同一成员函数的指针：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> Base
<span class="br0">{</span>
    <span class="kw4">void</span> f<span class="br0">(</span><span class="kw4">int</span> n<span class="br0">)</span> <span class="br0">{</span> <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> n <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="br0">}</span>
<span class="br0">}</span><span class="sy4">;</span>
<span class="kw1">struct</span> Derived <span class="sy4">:</span> Base <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">void</span> <span class="br0">(</span>Base<span class="sy4">::</span><span class="sy2">*</span> bp<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>Base<span class="sy4">::</span><span class="me2">f</span><span class="sy4">;</span>
    <span class="kw4">void</span> <span class="br0">(</span>Derived<span class="sy4">::</span><span class="sy2">*</span> dp<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> bp<span class="sy4">;</span>
    Derived d<span class="sy4">;</span>
    <span class="br0">(</span>d.<span class="sy2">*</span>dp<span class="br0">)</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy4">;</span>
    <span class="br0">(</span>d.<span class="sy2">*</span>bp<span class="br0">)</span><span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>相反方向的转换，即从指向派生类的成员函数的指针到指向无歧义非虚基类的成员函数的指针，允许由 <a href="static_cast.html" title="cpp/language/static cast">static_cast</a> 与<a href="explicit_cast.html" title="cpp/language/explicit cast">显式转型</a>来进行，即使基类无该成员函数（但在用该指针进行访问时，最终派生类有）：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> Base <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span>
<span class="kw1">struct</span> Derived <span class="sy4">:</span> Base
<span class="br0">{</span>
    <span class="kw4">void</span> f<span class="br0">(</span><span class="kw4">int</span> n<span class="br0">)</span> <span class="br0">{</span> <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> n <span class="sy1">&lt;&lt;</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span> <span class="br0">}</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">void</span> <span class="br0">(</span>Derived<span class="sy4">::</span><span class="sy2">*</span> dp<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>Derived<span class="sy4">::</span><span class="me2">f</span><span class="sy4">;</span>
    <span class="kw4">void</span> <span class="br0">(</span>Base<span class="sy4">::</span><span class="sy2">*</span> bp<span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">=</span> <span class="kw1">static_cast</span><span class="sy1">&lt;</span><span class="kw4">void</span> <span class="br0">(</span>Base<span class="sy4">::</span><span class="sy2">*</span><span class="br0">)</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span><span class="sy1">&gt;</span><span class="br0">(</span>dp<span class="br0">)</span><span class="sy4">;</span>
 
    Derived d<span class="sy4">;</span>
    <span class="br0">(</span>d.<span class="sy2">*</span>bp<span class="br0">)</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// OK：打印 1</span>
 
    Base b<span class="sy4">;</span>
    <span class="br0">(</span>b.<span class="sy2">*</span>bp<span class="br0">)</span><span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// 未定义行为</span>
<span class="br0">}</span></pre></div></div>
<p>成员函数指针可用作回调或函数对象，通常在应用 <span class="t-lc"><a href="../utility/functional/mem_fn.html" title="cpp/utility/functional/mem fn">std::mem_fn</a></span> 或 <span class="t-lc"><a href="../utility/functional/bind.html" title="cpp/utility/functional/bind">std::bind</a></span> 之后：
</p>
<div class="t-example"><div class="t-example-live-link"><div class="coliru-btn coliru-btn-run-init">运行此代码</div></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="co2">#include &lt;iostream&gt;</span>
<span class="co2">#include &lt;string&gt;</span>
<span class="co2">#include &lt;algorithm&gt;</span>
<span class="co2">#include &lt;functional&gt;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <a href="../container/vector.html"><span class="kw1269">std::<span class="me2">vector</span></span></a><span class="sy1">&lt;</span><a href="../string/basic_string.html"><span class="kw1230">std::<span class="me2">string</span></span></a><span class="sy1">&gt;</span> v <span class="sy1">=</span> <span class="br0">{</span><span class="st0">"a"</span>, <span class="st0">"ab"</span>, <span class="st0">"abc"</span><span class="br0">}</span><span class="sy4">;</span>
    <a href="../container/vector.html"><span class="kw1269">std::<span class="me2">vector</span></span></a><span class="sy1">&lt;</span><a href="../types/size_t.html"><span class="kw100">std::<span class="me2">size_t</span></span></a><span class="sy1">&gt;</span> l<span class="sy4">;</span>
    transform<span class="br0">(</span>v.<span class="me1">begin</span><span class="br0">(</span><span class="br0">)</span>, v.<span class="me1">end</span><span class="br0">(</span><span class="br0">)</span>, <a href="../iterator/back_inserter.html"><span class="kw665">std::<span class="me2">back_inserter</span></span></a><span class="br0">(</span>l<span class="br0">)</span>,
              <a href="../utility/functional/mem_fn.html"><span class="kw1057">std::<span class="me2">mem_fn</span></span></a><span class="br0">(</span><span class="sy3">&amp;</span>std<span class="sy4">::</span><span class="me2">string</span><span class="sy4">::</span><span class="me2">size</span><span class="br0">)</span><span class="br0">)</span><span class="sy4">;</span>
    <span class="kw1">for</span><span class="br0">(</span><a href="../types/size_t.html"><span class="kw100">std::<span class="me2">size_t</span></span></a> n <span class="sy4">:</span> l<span class="br0">)</span>
        <a href="../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> n <span class="sy1">&lt;&lt;</span> <span class="st0">' '</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>输出：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="text source-text"><pre class="de1">1 2 3</pre></div></div> 
</div>
<h3><span class="mw-headline" id=".E7.A9.BA.E6.8C.87.E9.92.88">空指针</span></h3>
<p>每个类型的指针都拥有一个特殊值，称为该类型的<i>空指针值（null pointer value）</i>。值为空的指针不指向对象或函数（解引用空指针是未定义行为），并与所有亦为<i>空</i>值的同类型指针比较相等。
</p><p>为将指针初始化为空或赋空值给既存指针，可以使用空指针字面量 <span class="t-c"><span class="mw-geshi cpp source-cpp">nullptr</span></span>、空指针常量 <span class="t-lc"><a href="../types/NULL.html" title="cpp/types/NULL">NULL</a></span> 或从整数值 <span class="t-c"><span class="mw-geshi cpp source-cpp">​<span class="nu0">0</span>​</span></span> 的<a href="implicit_cast.html" title="cpp/language/implicit conversion">隐式转换</a>。
</p><p><a href="zero_initialization.html" title="cpp/language/zero initialization">零初始化</a>和<a href="value_initialization.html" title="cpp/language/value initialization">值初始化</a>亦将指针初始化为其空值。
</p><p>空指针可用于指示对象不存在（例如 <a href="../utility/functional/function/target.html" title="cpp/utility/functional/function/target"><tt>function::target()</tt></a>），或作为其他错误条件的指示器（例如 <a href="dynamic_cast.html" title="cpp/language/dynamic cast">dynamic_cast</a>）。通常，接受指针实参的函数始终需要检查值是否为空，并以不同方式处理该情况（例如，<a href="delete.html" title="cpp/language/delete">delete 表达式</a>在传递空指针时不做任何事）。
</p>
<h3><span class="mw-headline" id=".E5.B8.B8.E9.87.8F.E6.80.A7">常量性</span></h3>
<ul><li> 若指针声明中 <span class="t-spar">cv</span> 在 <code><b>*</b></code> 之前出现，则它是 <span class="t-spar">声明说明符序列</span> 的一部分，并应用到被指向的对象。
</li><li> 若指针声明中 <span class="t-spar">cv</span> 在 <code><b>*</b></code> 之后出现，则它是 <span class="t-spar">声明符</span> 的一部分，并应用到所声明的指针。
</li></ul>
<table class="wikitable">

<tr>
<th>语法</th>
<th>含义
</th></tr>
<tr>
<td> <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">const</span> T<span class="sy2">*</span></span></span> </td>
<td>指向 const 对象的指针
</td></tr>
<tr>
<td> <span class="t-c"><span class="mw-geshi cpp source-cpp">T <span class="kw4">const</span><span class="sy2">*</span></span></span> </td>
<td>指向 const 对象的指针
</td></tr>
<tr>
<td> <span class="t-c"><span class="mw-geshi cpp source-cpp">T<span class="sy2">*</span> <span class="kw4">const</span></span></span> </td>
<td>指向对象的 const 指针
</td></tr>
<tr>
<td> <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">const</span> T<span class="sy2">*</span> <span class="kw4">const</span></span></span> </td>
<td>指向 const 对象的 const 指针
</td></tr>
<tr>
<td> <span class="t-c"><span class="mw-geshi cpp source-cpp">T <span class="kw4">const</span><span class="sy2">*</span> <span class="kw4">const</span></span></span> </td>
<td>指向 const 对象的 const 指针
</td></tr></table>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="co1">// pc 是 const int 的非 const 指针</span>
<span class="co1">// cpc 是 const int 的 const 指针</span>
<span class="co1">// ppc 是 const int 的非 const 指针的非 const 指针</span>
<span class="kw4">const</span> <span class="kw4">int</span> ci <span class="sy1">=</span> <span class="nu0">10</span>, <span class="sy2">*</span>pc <span class="sy1">=</span> <span class="sy3">&amp;</span>ci, <span class="sy2">*</span><span class="kw4">const</span> cpc <span class="sy1">=</span> pc, <span class="sy2">**</span>ppc<span class="sy4">;</span>
<span class="co1">// p 是非 const int 的非 const 指针</span>
<span class="co1">// cp 是非 const int 的 const 指针</span>
<span class="kw4">int</span> i, <span class="sy2">*</span>p, <span class="sy2">*</span><span class="kw4">const</span> cp <span class="sy1">=</span> <span class="sy3">&amp;</span>i<span class="sy4">;</span>
 
i <span class="sy1">=</span> ci<span class="sy4">;</span>    <span class="co1">// OK：复制 const int 值到非 const int</span>
<span class="sy2">*</span>cp <span class="sy1">=</span> ci<span class="sy4">;</span>  <span class="co1">// OK：能修改非 const int（为 const 指针所指向）</span>
pc<span class="sy2">++</span><span class="sy4">;</span>      <span class="co1">// OK：能修改非 const 指针（指向 const int）</span>
pc <span class="sy1">=</span> cpc<span class="sy4">;</span>  <span class="co1">// OK：能修改非 const 指针（指向 const int）</span>
pc <span class="sy1">=</span> p<span class="sy4">;</span>    <span class="co1">// OK：能修改非 const 指针（指向 const int）</span>
ppc <span class="sy1">=</span> <span class="sy3">&amp;</span>pc<span class="sy4">;</span> <span class="co1">// OK：const int 的指针的地址是 const int 的指针的指针</span>
 
ci <span class="sy1">=</span> <span class="nu0">1</span><span class="sy4">;</span>    <span class="co1">// 错误：不能修改 const int</span>
ci<span class="sy2">++</span><span class="sy4">;</span>      <span class="co1">// 错误：不能修改 const int</span>
<span class="sy2">*</span>pc <span class="sy1">=</span> <span class="nu0">2</span><span class="sy4">;</span>   <span class="co1">// 错误：不能修改被指向的 const int</span>
cp <span class="sy1">=</span> <span class="sy3">&amp;</span>ci<span class="sy4">;</span>  <span class="co1">// 错误：不能修改 const 指针（指向非 const int）</span>
cpc<span class="sy2">++</span><span class="sy4">;</span>     <span class="co1">// 错误：不能修改 const 指针（指向 const int）</span>
p <span class="sy1">=</span> pc<span class="sy4">;</span>    <span class="co1">// 错误：非 const int 的指针不能指向 const int</span>
ppc <span class="sy1">=</span> <span class="sy3">&amp;</span>p<span class="sy4">;</span>  <span class="co1">// 错误：const int 的指针的指针不能指向非 const int 的指针</span></pre></div></div>
<p>通常，从一个多级指针到另一个的隐式转换，遵循<a href="implicit_cast.html#.E9.99.90.E5.AE.9A.E8.BD.AC.E6.8D.A2" title="cpp/language/implicit conversion">限定转换</a>和<a href="operator_comparison.html#.E6.8C.87.E9.92.88.E6.AF.94.E8.BE.83.E8.BF.90.E7.AE.97.E7.AC.A6" title="cpp/language/operator comparison">指针比较运算符</a>中所描述的规则。
</p>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>
<table class="t-dsc-begin">

</table>

<!-- 
NewPP limit report
Preprocessor visited node count: 3830/1000000
Preprocessor generated node count: 8796/1000000
Post‐expand include size: 79131/2097152 bytes
Template argument size: 19881/2097152 bytes
Highest expansion depth: 15/40
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_zh_:pcache:idhash:2744-0!*!0!!zh!*!zh!* and timestamp 20200206113745 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    来自“<a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/language/pointer&amp;oldid=59975">https://zh.cppreference.com/mwiki/index.php?title=cpp/language/pointer&amp;oldid=59975</a>”                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        <div id="cpp-footer-base" class="noprint">
            <div id="footer">
                        <div id="cpp-navigation">
            <h5>导航</h5>
            <ul><li><a href="https://zh.cppreference.com/w/cpp/language/pointer">Online version</a></li><li>Offline version retrieved 2020-03-14 18:00.</li></ul></div>
                        <ul id="footer-info">
                                    <li id="footer-info-lastmod"> 本页面最后修改于2019年4月20日 (星期六) 23:10。</li>
                                    <li id="footer-info-viewcount">此页面已被浏览过8,469次。</li>
                            </ul>
                    </div>
        </div>
        <!-- /footer -->
        <script>if(window.mw){
mw.loader.state({"site":"loading","user":"missing","user.groups":"ready"});
}</script>
<script src="../../../common/skin_scripts.js"></script>
<script>if(window.mw){
mw.loader.load(["mediawiki.action.view.postEdit","mediawiki.user","mediawiki.page.ready","mediawiki.searchSuggest","mediawiki.hidpi","ext.gadget.MathJax","ext.gadget.ColiruCompiler"], null, true);
}</script>
<script src="../../../common/site_scripts.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2828341-1']);
_gaq.push(['_setDomainName', 'cppreference.com']);
_gaq.push(['_trackPageview']);
</script><!-- Served in 2.519 secs. -->
	</body>
<!-- Cached 20200206113745 -->
</html>